import React from "react";

import { fetchData, ajax} from '../../common';

import {Badge,Select} from 'antd';

import UIIcon from '../../uicomponents/UIIcon';

const Option = Select.Option;

/** 
 * 产品模型包选择
*/
export default class ProductModelPackageSelect extends React.Component {

	constructor(props) {
		super(props);
		this.modelPackageList = fetchData('PRODUCT/MODEL/productModelPackage/getModelPackages', {domainId : props.domainId,packageType : props.packageType});
	}


	renderModelPackage = (modelPackage) => {
		let color = "processing";
		if ('IN_USE' === modelPackage.status) {
			color = 'processing'
		}
		else if ('CLOSED' === modelPackage.status) {
			color = 'error'
		}

		return (<Badge status={color} style={{ marginLeft: 6 }} text={<span><UIIcon icon='folder' />{modelPackage.packageName}</span>} />)
	}

	handleSelect = (value, opt) => {
		if (this.props.onSelectModelPackage) {
			this.props.onSelectModelPackage(value);
		}
	}

	render() {
		const { modelPackageList } = this;
		return (
			<Select style={{ width: '100%' }}
				onSelect={this.handleSelect}
				placeholder="请选择模型包"
			>
				{modelPackageList.map(modelPackage => (
					<Option key={'modelPackage' + modelPackage.id} value={modelPackage.id}>{this.renderModelPackage(modelPackage)}</Option>
				))}
			</Select>
		);
	}
}
